/*
 * Created by JFormDesigner on Fri Jun 28 14:56:46 CST 2024
 */

package scct.chenlixian.ui;

import scct.chenlixian.dao.TypeDao;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @author DELL
 */
public class DlgADDType extends JDialog {
    public DlgADDType(Window owner) {
        super(owner);
        initComponents();
    }

    private void button1(ActionEvent e) {
        String name = txtName.getText();
        String remark = txtRemark.getText();
        if(name.length()==0)
        {
            JOptionPane.showMessageDialog(this,"请输入正确的类别");
            return;
        }
        TypeDao typeDao=new TypeDao();
        if(typeDao.addType(name,remark))
        {
            JOptionPane.showMessageDialog(this,"成功添加类别");
        }
        dispose();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - CLX
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        label1 = new JLabel();
        label2 = new JLabel();
        txtName = new JTextField();
        scrollPane1 = new JScrollPane();
        txtRemark = new JTextArea();
        button1 = new JButton();
        button2 = new JButton();
        buttonBar = new JPanel();
        okButton = new JButton();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setBorder (new javax. swing. border. CompoundBorder( new javax .swing .border .TitledBorder (new javax. swing. border. EmptyBorder(
            0, 0, 0, 0) , "JFor\u006dDesi\u0067ner \u0045valu\u0061tion", javax. swing. border. TitledBorder. CENTER, javax. swing. border. TitledBorder
            . BOTTOM, new java .awt .Font ("Dia\u006cog" ,java .awt .Font .BOLD ,12 ), java. awt. Color.
            red) ,dialogPane. getBorder( )) ); dialogPane. addPropertyChangeListener (new java. beans. PropertyChangeListener( ){ @Override public void propertyChange (java .
            beans .PropertyChangeEvent e) {if ("bord\u0065r" .equals (e .getPropertyName () )) throw new RuntimeException( ); }} );
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(null);

                //---- label1 ----
                label1.setText("\u7c7b\u522b\u540d\u79f0");
                contentPanel.add(label1);
                label1.setBounds(new Rectangle(new Point(65, 25), label1.getPreferredSize()));

                //---- label2 ----
                label2.setText("\u7c7b\u522b\u8bf4\u660e");
                contentPanel.add(label2);
                label2.setBounds(70, 55, label2.getPreferredSize().width, 35);
                contentPanel.add(txtName);
                txtName.setBounds(145, 15, 190, 40);

                //======== scrollPane1 ========
                {
                    scrollPane1.setViewportView(txtRemark);
                }
                contentPanel.add(scrollPane1);
                scrollPane1.setBounds(130, 65, 220, 115);

                //---- button1 ----
                button1.setText("\u7c7b\u522b\u6dfb\u52a0");
                button1.addActionListener(e -> button1(e));
                contentPanel.add(button1);
                button1.setBounds(new Rectangle(new Point(85, 195), button1.getPreferredSize()));

                //---- button2 ----
                button2.setText("\u53d6\u6d88");
                contentPanel.add(button2);
                button2.setBounds(new Rectangle(new Point(255, 195), button2.getPreferredSize()));

                {
                    // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < contentPanel.getComponentCount(); i++) {
                        Rectangle bounds = contentPanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = contentPanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    contentPanel.setMinimumSize(preferredSize);
                    contentPanel.setPreferredSize(preferredSize);
                }
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
                ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};

                //---- okButton ----
                okButton.setText("OK");
                buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - CLX
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel label1;
    private JLabel label2;
    private JTextField txtName;
    private JScrollPane scrollPane1;
    private JTextArea txtRemark;
    private JButton button1;
    private JButton button2;
    private JPanel buttonBar;
    private JButton okButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
